<?php
/**
 * Created by PhpStorm.
 * User: work
 * Date: 18-7-21
 * Time: 下午10:25
 */

namespace PddWechat\Library;


use Dai\Framework\Library\RedisExt;

class MsgLibrary
{
    public static function getCustomerMsg($nickName=""){
        if( $nickName != "") {
            $nickName = "@$nickName,";
        }

        $goodsIds = RedisExt::getInstance()->get("hot_goods_ids");
        $goodsIds = explode(",", $goodsIds);

        $msgs[] = [
            'title' => "$nickName 转盘抽大奖,幸运迎免单",
            'url' => "https://mobile.yangkeduo.com/duo_roulette.html?pid=1884871_22329699&cpsSign=CL1884871_22329699_84873959b2324bc085f9a89376d8c668&duoduo_type=2",         'description' => '转盘抽大奖，幸运迎免单',
            'picurl' => 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1536691776753&di=bd2552f6c69ed4e5535d548cfeafa719&imgtype=0&src=http%3A%2F%2Fpic.qiantucdn.com%2F58pic%2F26%2F19%2F45%2F83Y58PICBwr_1024.jpg',
        ];

        foreach ($goodsIds as $goodsId) {
            $goodsInfoStr = RedisExt::getInstance()->get("hot_goods_detail_$goodsId");
            if( trim($goodsInfoStr) == "") {
                continue;
            }
            $goodsInfo = json_decode($goodsInfoStr, true);
            if( $goodsInfo['goodsId'] > 0) {
                $price = round(($goodsInfo['minGroupPrice']-$goodsInfo['couponMinOrderAmount'])/1000,2);
                $promotion = round($price * $goodsInfo['promotionRate'] /1000 * 0.4,2);
                $title = "[券后价] $price 元,[返现]$promotion 元,". $goodsInfo['goodsName'];
                $msgs[] = [
                    'title' => $title,
                    'description'  => $title,
                    'picurl' => $goodsInfo['goodsImageUrl'],
                    'url' => 'http://pdd.keepfoolish.cn/mall/goods?goodsId='.$goodsInfo['goodsId'],
                ];
            }
        }
        return $msgs;
    }
}